package com.easytopit.demo.lianxi.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.easytopit.demo.lianxi.exception.BizException;
import com.easytopit.demo.lianxi.service.UserService;
import com.easytopit.demo.lianxi.user.User;

@Controller
public class UserController {
	
	@Autowired
	private UserService userService;
	
	@RequestMapping("/add.do")
	public void add(User user, HttpServletResponse response){
		response.setCharacterEncoding("UTF-8");
		try{
			Integer insert = userService.insert(user);
			if(insert == null){
				response.getWriter().write(JSONObject.toJSONString("添加失败").toString());
			}else{
				response.getWriter().write(JSONObject.toJSONString("ok").toString());
			}
		} catch (BizException | IOException e) {
			e.printStackTrace();
		}
	}
	
	@RequestMapping("/query.do")
	public void query(String name, Integer pageIndex, Integer pageSize, ModelMap map, HttpServletResponse response){
		response.setCharacterEncoding("UTF-8");
		try {
			
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
}
